//
//  NibLoadable.swift
//  RxDemo
//
//  Created by MAC on 2019/5/27.
//  Copyright © 2019 zk. All rights reserved.
//

import UIKit

protocol NibLoadable { }

extension NibLoadable where Self: UIView {
    
    static func loadFromNib(_ nibName: String? = nil) -> Self {
        return Bundle.main.loadNibNamed(nibName ?? "\(self)", owner: nil, options: nil)?.first as! Self
    }
    
    static func nib() -> UINib {
        
        return UINib(nibName: self.nameOfClass, bundle: nil)
    }
}

//MARK: - 类名同名ID
extension UIView {
    
    //用于获取 cell 的 reuse identifier
    class var identifier: String {
        return String(format: "%@", self.nameOfClass)
    }
    
    class var nameOfClass: String {
        return NSStringFromClass(self).components(separatedBy: ".").last! as String
    }
}
